To learn how to integrate files that have pure postscript commands.
To illistrate that variables from the View superclass are accessable.
Terms:
.psw: Postscript wrap files - files with pure ASCII postscript.
Discussion:
By creating a file with the ".psw" extension, we can call complex
postscript procedures directly from our Objective C programs.
Method:
1) Take the original "line" program and create the file line.psw which
contains the following lines:
defineps doLine(float x,y)
5 setlinewidth
newpath
100 100 moveto
x y lineto
stroke
endps
Then added the file "line.psw" to the project manager by going to the
Files/Project... menu, selecting Files from the top button and then selecting
.psw files from the pop up menu. Once .psw Files button is showing we then select the Add... button at the bottum which will bring up an open panel. We then select the line.psw file.
The drawSelf routine is then changed to be the following:
- drawSelf:(NXRect*)r :(int)c
{
PSsetgray(1.0);
NXRectFill(r);
PSsetgray(0.0);
doLine(200.0, 200.0);
return self;
}
We also add the include file "line.h" created from line.psw to the
myView.m file:
#import "line.h"
When you type "make" you will see the following additional commands get
executed:
pswrap -h line.h -o line.c line.psw
cc -O -Wimplicit -c line.c -o obj/line.o
You should still see the line being drawn after you execute line.
Part II - finding the center of the view
What if you wanted to draw a line from the exact center of the View?
Since the bounds of the view are kept in the View superclass, all we have
to do is use those variables. This can be done by changing the argument